package com.ganzalang.gmall.designpatterns.factory.abstractfactory;

import com.ganzalang.gmall.designpatterns.factory.methodfactory.MethodFactoryPatternDemo;
import lombok.extern.slf4j.Slf4j;

/**
 * @description: 使用抽象工厂
 */
@Slf4j
public class AbstractFactoryPatternDemo {


    public static void main(String[] args) {
        ProductA productA = new Product1Factory().createProductA();
        ProductB productB = new Product1Factory().createProductB();
        productA.execute();
        productB.execute();
    }

    public interface ProductA {
        void execute();
    }

    public interface ProductB {
        void execute();
    }

    public static class ProductA1 implements ProductA {

        @Override
        public void execute() {
            log.info("执行A1方法");
        }
    }

    public static class ProductA2 implements ProductA {

        @Override
        public void execute() {
            log.info("执行A2方法");
        }
    }

    public static class ProductA3 implements ProductA {

        @Override
        public void execute() {
            log.info("执行A3方法");
        }
    }

    public static class ProductB1 implements ProductB {

        @Override
        public void execute() {
            log.info("执行B1方法");
        }
    }

     public static class ProductB2 implements ProductB {

        @Override
        public void execute() {
            log.info("执行B2方法");
        }
    }

     public static class ProductB3 implements ProductB {

        @Override
        public void execute() {
            log.info("执行B3方法");
        }
    }

    /**
     * 现在确定这个产品就是产品A+产品B的组合的，所以这个抽象类里面就是创建A和创建B
     */
    public static abstract class AbstractProductFactory {
        protected abstract ProductA createProductA();
        protected abstract ProductB createProductB();
    }

    public static class Product1Factory extends AbstractProductFactory {

        @Override
        protected ProductA createProductA() {
            return new ProductA1();
        }

        @Override
        protected ProductB createProductB() {
            return new ProductB1();
        }
    }



}
